package com.gxa.system_setting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.R;
import com.gxa.common.entity.system_settings.Dropdown;
import com.gxa.system_setting.mapper.DropdownMapper;
import com.gxa.system_setting.service.DropdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DropdownServiceImpl implements DropdownService {

    @Autowired
    private DropdownMapper dropdownMapper;

    @Override
    public R DropdownList(Integer currentPage, Integer pageSize) {
        R r=new R();
        Page page=new Page(currentPage,pageSize);
        Page dropdownList = dropdownMapper.selectPage(page,null);
        r.setCode(200);
        r.setMessage("分页查询成功");
        r.setData(dropdownList);
        return r;
    }

    @Override
    public R updateDropdown(Dropdown dropdown) {
        R r=new R();
        int i = dropdownMapper.updateById(dropdown);
        r.setCode(200);
        r.setMessage("修改成功");
        return r;
    }

    @Override
    public R stopOrUseDropdown(Long dropdownId, Long flag) {
        R r=new R();
        int i=dropdownMapper.stopOrUseDropdown(dropdownId,flag);
        r.setCode(200);
        r.setMessage("禁用/启用成功");
        return r;
    }

    @Override
    public R selectDropdownByConditions(Dropdown dropdown) {
        R r=new R();
        QueryWrapper<Dropdown> queryWrapper=new QueryWrapper();
        queryWrapper.and((wrapper)->{
            wrapper.like("key_zhi",dropdown.getKeyZhi())
                    .or().like("value_zhi",dropdown.getValueZhi())
                    .or().like("remarks_zhi",dropdown.getRemarksZhi());
        });
        queryWrapper.eq("status",dropdown.getStatus());
        List list = dropdownMapper.selectList(queryWrapper);
        r.setCode(200);
        r.setMessage("条件查询车工");
        r.setData(list);
        return r;
    }
}
